home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / Miro_Downloader.exe / hashlib.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-11-12  |  2.8 KB  |  105 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. """hashlib module - A common interface to many hash functions.
  5.  
  6. new(name, string='') - returns a new hash object implementing the
  7.                        given hash function; initializing the hash
  8.                        using the given string data.
  9.  
  10. Named constructor functions are also available, these are much faster
  11. than using new():
  12.  
  13. md5(), sha1(), sha224(), sha256(), sha384(), and sha512()
  14.  
  15. More algorithms may be available on your platform but the above are
  16. guaranteed to exist.
  17.  
  18. Choose your hash function wisely.  Some have known weaknesses.
  19. sha384 and sha512 will be slow on 32 bit platforms.
  20. """
  21.  
  22. def __get_builtin_constructor(name):
  23.     if name in ('SHA1', 'sha1'):
  24.         import _sha
  25.         return _sha.new
  26.     elif name in ('MD5', 'md5'):
  27.         import _md5
  28.         return _md5.new
  29.     elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'):
  30.         import _sha256
  31.         bs = name[3:]
  32.         if bs == '256':
  33.             return _sha256.sha256
  34.         elif bs == '224':
  35.             return _sha256.sha224
  36.         
  37.     elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'):
  38.         import _sha512
  39.         bs = name[3:]
  40.         if bs == '512':
  41.             return _sha512.sha512
  42.         elif bs == '384':
  43.             return _sha512.sha384
  44.         
  45.     
  46.     raise ValueError, 'unsupported hash type'
  47.  
  48.  
  49. def __py_new(name, string = ''):
  50.     """new(name, string='') - Return a new hashing object using the named algorithm;
  51.     optionally initialized with a string.
  52.     """
  53.     return __get_builtin_constructor(name)(string)
  54.  
  55.  
  56. def __hash_new(name, string = ''):
  57.     """new(name, string='') - Return a new hashing object using the named algorithm;
  58.     optionally initialized with a string.
  59.     """
  60.     
  61.     try:
  62.         return _hashlib.new(name, string)
  63.     except ValueError:
  64.         return __get_builtin_constructor(name)(string)
  65.  
  66.  
  67.  
  68. try:
  69.     import _hashlib
  70.     new = __hash_new
  71.     for opensslFuncName in filter((lambda n: n.startswith('openssl_')), dir(_hashlib)):
  72.         funcName = opensslFuncName[len('openssl_'):]
  73.         
  74.         try:
  75.             f = getattr(_hashlib, opensslFuncName)
  76.             f()
  77.             exec funcName + ' = f'
  78.         continue
  79.         except ValueError:
  80.             
  81.             try:
  82.                 exec funcName + ' = __get_builtin_constructor(funcName)'
  83.             except ValueError:
  84.                 pass
  85.             except:
  86.                 None<EXCEPTION MATCH>ValueError
  87.             
  88.  
  89.             None<EXCEPTION MATCH>ValueError
  90.         
  91.  
  92.     
  93.     del f
  94.     del opensslFuncName
  95.     del funcName
  96. except ImportError:
  97.     new = __py_new
  98.     md5 = __get_builtin_constructor('md5')
  99.     sha1 = __get_builtin_constructor('sha1')
  100.     sha224 = __get_builtin_constructor('sha224')
  101.     sha256 = __get_builtin_constructor('sha256')
  102.     sha384 = __get_builtin_constructor('sha384')
  103.     sha512 = __get_builtin_constructor('sha512')
  104.  
  105.